package com.spddr.pmos.jpa;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import cn.seqdata.jpa.AbstractPersistable;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Entity
@Table(name = "role_permission")
public class RolePermission extends AbstractPersistable<RolePermissionId> {
	private static final long serialVersionUID = 1L;

	private Role role;
	private Permission permission;

	public RolePermission() {
	}

	public RolePermission(long role, int permission) {
		setId(new RolePermissionId(role, permission));
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "role", nullable = false, insertable = false, updatable = false)
	@JsonSerialize(using = cn.seqdata.jackson.ObjectSerializer.IdName.class)
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "permisssion", nullable = false, insertable = false, updatable = false)
	@JsonSerialize(using = cn.seqdata.jackson.ObjectSerializer.IdName.class)
	public Permission getPermission() {
		return this.permission;
	}

	public void setPermission(Permission permission) {
		this.permission = permission;
	}
}